﻿using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FitAutomation.Tests
{
	[TestClass]
	public class UnitTest1
	{
		public class MyClass// : MarshalByRefObject
		{
			public int ProcessId
			{
				get { return Process.GetCurrentProcess().Id; }
			}

			public string UserName
			{
				get { return Environment.UserName; }
			}

			public void Shutdown()
			{
				// System.Windows.Application.Shutdown();
			}

			public string Download(string url)
			{
				return null;
			}
		}

		private readonly MyClass _my = new MyClass();

		[TestMethod]
		[Ignore]
		public void Should_use_another_process_for_call()
		{
			var remoteProcessId = FitAutomationFacade.Call<MyClass>("", "", "").CallReflect<int>("ProcessId");
			Assert.IsTrue(remoteProcessId > 0);
			Assert.AreNotEqual(_my.ProcessId, remoteProcessId);
		}

		[TestMethod]
		[Ignore]
		public void Should_try_download_some_web_page_under_specified_user_session()
		{
			var result = FitAutomationFacade.Call<MyClass>("vm-121-nick", "OneToOne.Client").CallReflect<string>("Download", "http://ya.ru");
			StringAssert.Contains(result, "Яндекс");
		}

		[TestMethod]
		[Ignore]
		public void Should_shutdown_121()
		{
			FitAutomationFacade.Call<MyClass>("vm-121-nick", "OneToOne.Client").CallReflect("Shutdown");
			Assert.Inconclusive();
		}

		[TestMethod]
		public void Should_execute_code_on_another_machine()
		{
			var machineName = FitAutomationFacade.Call("vm-121-michel", "", () => Environment.MachineName+"!");
			Assert.AreEqual("vm-121-michel!", machineName);
		}
	}
}
